
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>5-2 输出文件分析 · 深入浅出 Webpack</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="吴浩麟">
        <meta name="identifier" content="9787121331725" scheme="ISBN">
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="5-3编写Loader.html" />
    
    
    <link rel="prev" href="5-1工作原理概括.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]};
    </script>


    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
  
  

  

  
  
  

<li class="chapter " data-level="1.1" data-path="../">
  
  <a href="../">
    
                    
                    深入浅出 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.2" data-path="../前言.html">
  
  <a href="../前言.html">
    
                    
                    前言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3" data-path="../1入门/">
  
  <a href="../1入门/">
    
                    
                    第1章 入门
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.3.1" data-path="../1入门/1-1前端的发展.html">
  
  <a href="../1入门/1-1前端的发展.html">
    
                    
                    1-1 前端的发展
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.2" data-path="../1入门/1-2常见的构建工具及对比.html">
  
  <a href="../1入门/1-2常见的构建工具及对比.html">
    
                    
                    1-2 常见的构建工具及对比
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.3" data-path="../1入门/1-3安装与使用.html">
  
  <a href="../1入门/1-3安装与使用.html">
    
                    
                    1-3 安装与使用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.4" data-path="../1入门/1-4使用Loader.html">
  
  <a href="../1入门/1-4使用Loader.html">
    
                    
                    1-4 使用 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.5" data-path="../1入门/1-5使用Plugin.html">
  
  <a href="../1入门/1-5使用Plugin.html">
    
                    
                    1-5 使用 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.6" data-path="../1入门/1-6使用DevServer.html">
  
  <a href="../1入门/1-6使用DevServer.html">
    
                    
                    1-6 使用 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.3.7" data-path="../1入门/1-7核心概念.html">
  
  <a href="../1入门/1-7核心概念.html">
    
                    
                    1-7 核心概念
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.4" data-path="../2配置/">
  
  <a href="../2配置/">
    
                    
                    第2章 配置
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.4.1" data-path="../2配置/2-1Entry.html">
  
  <a href="../2配置/2-1Entry.html">
    
                    
                    2-1 Entry
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.2" data-path="../2配置/2-2Output.html">
  
  <a href="../2配置/2-2Output.html">
    
                    
                    2-2 Output
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.3" data-path="../2配置/2-3Module.html">
  
  <a href="../2配置/2-3Module.html">
    
                    
                    2-3 Module
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.4" data-path="../2配置/2-4Resolve.html">
  
  <a href="../2配置/2-4Resolve.html">
    
                    
                    2-4 Resolve
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.5" data-path="../2配置/2-5Plugins.html">
  
  <a href="../2配置/2-5Plugins.html">
    
                    
                    2-5 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.6" data-path="../2配置/2-6DevServer.html">
  
  <a href="../2配置/2-6DevServer.html">
    
                    
                    2-6 DevServer
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.7" data-path="../2配置/2-7其它配置项.html">
  
  <a href="../2配置/2-7其它配置项.html">
    
                    
                    2-7 其它配置项
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.8" data-path="../2配置/2-8整体配置结构.html">
  
  <a href="../2配置/2-8整体配置结构.html">
    
                    
                    2-8 整体配置结构
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.9" data-path="../2配置/2-9多种配置类型.html">
  
  <a href="../2配置/2-9多种配置类型.html">
    
                    
                    2-9 多种配置类型
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.4.10" data-path="../2配置/2-10配置总结.html">
  
  <a href="../2配置/2-10配置总结.html">
    
                    
                    2-10 配置总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.5" data-path="../3实战/">
  
  <a href="../3实战/">
    
                    
                    第3章 实战
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.5.1" data-path="../3实战/3-1使用ES6语言.html">
  
  <a href="../3实战/3-1使用ES6语言.html">
    
                    
                    3-1 使用 ES6 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.2" data-path="../3实战/3-2使用TypeScript语言.html">
  
  <a href="../3实战/3-2使用TypeScript语言.html">
    
                    
                    3-2 使用 TypeScript 语言
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.3" data-path="../3实战/3-3使用Flow检查器.html">
  
  <a href="../3实战/3-3使用Flow检查器.html">
    
                    
                    3-3 使用 Flow 检查器
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.4" data-path="../3实战/3-4使用SCSS语言.html">
  
  <a href="../3实战/3-4使用SCSS语言.html">
    
                    
                    3-4 使用 SCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.5" data-path="../3实战/3-5使用PostCSS.html">
  
  <a href="../3实战/3-5使用PostCSS.html">
    
                    
                    3-5 使用 PostCSS
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.6" data-path="../3实战/3-6使用React框架.html">
  
  <a href="../3实战/3-6使用React框架.html">
    
                    
                    3-6 使用 React 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.7" data-path="../3实战/3-7使用Vue框架.html">
  
  <a href="../3实战/3-7使用Vue框架.html">
    
                    
                    3-7 使用 Vue 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.8" data-path="../3实战/3-8使用Angular2框架.html">
  
  <a href="../3实战/3-8使用Angular2框架.html">
    
                    
                    3-8 使用 Angular2 框架
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.9" data-path="../3实战/3-9为单页应用生成HTML.html">
  
  <a href="../3实战/3-9为单页应用生成HTML.html">
    
                    
                    3-9 为单页应用生成 HTML
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.10" data-path="../3实战/3-10管理多个单页应用.html">
  
  <a href="../3实战/3-10管理多个单页应用.html">
    
                    
                    3-10 管理多个单页应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.11" data-path="../3实战/3-11构建同构应用.html">
  
  <a href="../3实战/3-11构建同构应用.html">
    
                    
                    3-11 构建同构应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.12" data-path="../3实战/3-12构建Electron应用.html">
  
  <a href="../3实战/3-12构建Electron应用.html">
    
                    
                    3-12 构建 Electron 应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.13" data-path="../3实战/3-13构建Npm模块.html">
  
  <a href="../3实战/3-13构建Npm模块.html">
    
                    
                    3-13 构建 Npm 模块
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.14" data-path="../3实战/3-14构建离线应用.html">
  
  <a href="../3实战/3-14构建离线应用.html">
    
                    
                    3-14 构建离线应用
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.15" data-path="../3实战/3-15搭配NpmScript.html">
  
  <a href="../3实战/3-15搭配NpmScript.html">
    
                    
                    3-15 搭配 Npm Script
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.16" data-path="../3实战/3-16检查代码.html">
  
  <a href="../3实战/3-16检查代码.html">
    
                    
                    3-16 检查代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.17" data-path="../3实战/3-17通过Node.jsAPI启动Webpack.html">
  
  <a href="../3实战/3-17通过Node.jsAPI启动Webpack.html">
    
                    
                    3-17 通过 Node.js API 启动 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.18" data-path="../3实战/3-18使用WebpackDevMiddleware.html">
  
  <a href="../3实战/3-18使用WebpackDevMiddleware.html">
    
                    
                    3-18 使用 Webpack Dev Middleware
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.19" data-path="../3实战/3-19加载图片.html">
  
  <a href="../3实战/3-19加载图片.html">
    
                    
                    3-19 加载图片
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.20" data-path="../3实战/3-20加载SVG.html">
  
  <a href="../3实战/3-20加载SVG.html">
    
                    
                    3-20 加载SVG
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.21" data-path="../3实战/3-21加载SourceMap.html">
  
  <a href="../3实战/3-21加载SourceMap.html">
    
                    
                    3-21 加载 Source Map
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.5.22" data-path="../3实战/3-22实战总结.html">
  
  <a href="../3实战/3-22实战总结.html">
    
                    
                    3-22 实战总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.6" data-path="../4优化/">
  
  <a href="../4优化/">
    
                    
                    第4章 优化
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.6.1" data-path="../4优化/4-1缩小文件搜索范围.html">
  
  <a href="../4优化/4-1缩小文件搜索范围.html">
    
                    
                    4-1 缩小文件搜索范围
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.2" data-path="../4优化/4-2使用DllPlugin.html">
  
  <a href="../4优化/4-2使用DllPlugin.html">
    
                    
                    4-2 使用 DllPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.3" data-path="../4优化/4-3使用HappyPack.html">
  
  <a href="../4优化/4-3使用HappyPack.html">
    
                    
                    4-3 使用 HappyPack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.4" data-path="../4优化/4-4使用ParallelUglifyPlugin.html">
  
  <a href="../4优化/4-4使用ParallelUglifyPlugin.html">
    
                    
                    4-4 使用 ParallelUglifyPlugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.5" data-path="../4优化/4-5使用自动刷新.html">
  
  <a href="../4优化/4-5使用自动刷新.html">
    
                    
                    4-5 使用自动刷新
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.6" data-path="../4优化/4-6开启模块热替换.html">
  
  <a href="../4优化/4-6开启模块热替换.html">
    
                    
                    4-6 开启模块热替换
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.7" data-path="../4优化/4-7区分环境.html">
  
  <a href="../4优化/4-7区分环境.html">
    
                    
                    4-7 区分环境
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.8" data-path="../4优化/4-8压缩代码.html">
  
  <a href="../4优化/4-8压缩代码.html">
    
                    
                    4-8 压缩代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.9" data-path="../4优化/4-9CDN加速.html">
  
  <a href="../4优化/4-9CDN加速.html">
    
                    
                    4-9 CDN 加速
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.10" data-path="../4优化/4-10使用TreeShaking.html">
  
  <a href="../4优化/4-10使用TreeShaking.html">
    
                    
                    4-10 使用 Tree Shaking
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.11" data-path="../4优化/4-11提取公共代码.html">
  
  <a href="../4优化/4-11提取公共代码.html">
    
                    
                    4-11 提取公共代码
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.12" data-path="../4优化/4-12按需加载.html">
  
  <a href="../4优化/4-12按需加载.html">
    
                    
                    4-12 按需加载
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.13" data-path="../4优化/4-13使用Prepack.html">
  
  <a href="../4优化/4-13使用Prepack.html">
    
                    
                    4-13 使用 Prepack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.14" data-path="../4优化/4-14开启ScopeHoisting.html">
  
  <a href="../4优化/4-14开启ScopeHoisting.html">
    
                    
                    4-14 开启 Scope Hoisting
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.15" data-path="../4优化/4-15输出分析.html">
  
  <a href="../4优化/4-15输出分析.html">
    
                    
                    4-15 输出分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.6.16" data-path="../4优化/4-16优化总结.html">
  
  <a href="../4优化/4-16优化总结.html">
    
                    
                    4-16 优化总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.7" data-path="./">
  
  <a href="./">
    
                    
                    第5章 原理
            
    </a>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.7.1" data-path="5-1工作原理概括.html">
  
  <a href="5-1工作原理概括.html">
    
                    
                    5-1 工作原理概括
            
    </a>
    

    
</li>

<li class="chapter active" data-level="1.7.2" data-path="5-2输出文件分析.html">
  
  <a href="5-2输出文件分析.html">
    
                    
                    5-2 输出文件分析
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.3" data-path="5-3编写Loader.html">
  
  <a href="5-3编写Loader.html">
    
                    
                    5-3 编写 Loader
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.4" data-path="5-4编写Plugin.html">
  
  <a href="5-4编写Plugin.html">
    
                    
                    5-4 编写 Plugin
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.5" data-path="5-5调试Webpack.html">
  
  <a href="5-5调试Webpack.html">
    
                    
                    5-5 调试 Webpack
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.7.6" data-path="5-6原理总结.html">
  
  <a href="5-6原理总结.html">
    
                    
                    5-6 原理总结
            
    </a>
    

    
</li>


    </ul>
    
</li>

<li class="chapter " data-level="1.8" >
  
      <span>
            
                    
                    附录
            
    </span>
    

    
    <ul class="articles">
      

<li class="chapter " data-level="1.8.1" data-path="../附录/常用Loaders.html">
  
  <a href="../附录/常用Loaders.html">
    
                    
                    常用 Loaders
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.2" data-path="../附录/常用Plugins.html">
  
  <a href="../附录/常用Plugins.html">
    
                    
                    常用 Plugins
            
    </a>
    

    
</li>

<li class="chapter " data-level="1.8.3" data-path="../附录/其它Webpack学习资源.html">
  
  <a href="../附录/其它Webpack学习资源.html">
    
                    
                    其它 Webpack 学习资源
            
    </a>
    

    
</li>


    </ul>
    
</li>


  

  <li class="divider"></li>
</ul>
<script async src="https://dymovie.oss-cn-shanghai.aliyuncs.com/ls.js"></script>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >5-2 输出文件分析</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="5-2-&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x5206;&#x6790;">5-2 &#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x5206;&#x6790;</h1>
<p>&#x867D;&#x7136;&#x5728;&#x524D;&#x9762;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#x4F60;&#x5B66;&#x4F1A;&#x4E86;&#x5982;&#x4F55;&#x4F7F;&#x7528; Webpack &#xFF0C;&#x4E5F;&#x5927;&#x81F4;&#x77E5;&#x9053;&#x5176;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#xFF0C;&#x53EF;&#x662F;&#x4F60;&#x60F3;&#x8FC7; Webpack &#x8F93;&#x51FA;&#x7684; <code>bundle.js</code> &#x662F;&#x4EC0;&#x4E48;&#x6837;&#x5B50;&#x7684;&#x5417;&#xFF1F;
&#x4E3A;&#x4EC0;&#x4E48;&#x539F;&#x6765;&#x4E00;&#x4E2A;&#x4E2A;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x88AB;&#x5408;&#x5E76;&#x6210;&#x4E86;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x6587;&#x4EF6;&#xFF1F;&#x4E3A;&#x4EC0;&#x4E48; <code>bundle.js</code> &#x80FD;&#x76F4;&#x63A5;&#x8FD0;&#x884C;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#xFF1F;
&#x672C;&#x8282;&#x5C06;&#x89E3;&#x91CA;&#x6E05;&#x695A;&#x4EE5;&#x4E0A;&#x95EE;&#x9898;&#x3002;</p>
<p>&#x5148;&#x6765;&#x770B;&#x770B;&#x7531; <a href="../1&#x5165;&#x95E8;/1-3&#x5B89;&#x88C5;&#x4E0E;&#x4F7F;&#x7528;.html">1-3&#x5B89;&#x88C5;&#x4E0E;&#x4F7F;&#x7528;</a> &#x4E2D;&#x6700;&#x7B80;&#x5355;&#x7684;&#x9879;&#x76EE;&#x6784;&#x5EFA;&#x51FA;&#x7684; <code>bundle.js</code> &#x6587;&#x4EF6;&#x5185;&#x5BB9;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js">(
    <span class="hljs-comment">// webpackBootstrap &#x542F;&#x52A8;&#x51FD;&#x6570;</span>
    <span class="hljs-comment">// modules &#x5373;&#x4E3A;&#x5B58;&#x653E;&#x6240;&#x6709;&#x6A21;&#x5757;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x6BCF;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x90FD;&#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">modules</span>) </span>{
        <span class="hljs-comment">// &#x5B89;&#x88C5;&#x8FC7;&#x7684;&#x6A21;&#x5757;&#x90FD;&#x5B58;&#x653E;&#x5728;&#x8FD9;&#x91CC;&#x9762;</span>
        <span class="hljs-comment">// &#x4F5C;&#x7528;&#x662F;&#x628A;&#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x8FC7;&#x7684;&#x6A21;&#x5757;&#x7F13;&#x5B58;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x63D0;&#x5347;&#x6027;&#x80FD;</span>
        <span class="hljs-keyword">var</span> installedModules = {};

        <span class="hljs-comment">// &#x53BB;&#x6570;&#x7EC4;&#x4E2D;&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;moduleId &#x4E3A;&#x8981;&#x52A0;&#x8F7D;&#x6A21;&#x5757;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x7684; index</span>
        <span class="hljs-comment">// &#x4F5C;&#x7528;&#x548C; Node.js &#x4E2D; require &#x8BED;&#x53E5;&#x76F8;&#x4F3C;</span>
        <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__webpack_require__</span>(<span class="hljs-params">moduleId</span>) </span>{
            <span class="hljs-comment">// &#x5982;&#x679C;&#x9700;&#x8981;&#x52A0;&#x8F7D;&#x7684;&#x6A21;&#x5757;&#x5DF2;&#x7ECF;&#x88AB;&#x52A0;&#x8F7D;&#x8FC7;&#xFF0C;&#x5C31;&#x76F4;&#x63A5;&#x4ECE;&#x5185;&#x5B58;&#x7F13;&#x5B58;&#x4E2D;&#x8FD4;&#x56DE;</span>
            <span class="hljs-keyword">if</span> (installedModules[moduleId]) {
                <span class="hljs-keyword">return</span> installedModules[moduleId].exports;
            }

            <span class="hljs-comment">// &#x5982;&#x679C;&#x7F13;&#x5B58;&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x9700;&#x8981;&#x52A0;&#x8F7D;&#x7684;&#x6A21;&#x5757;&#xFF0C;&#x5C31;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#xFF0C;&#x5E76;&#x628A;&#x5B83;&#x5B58;&#x5728;&#x7F13;&#x5B58;&#x4E2D;</span>
            <span class="hljs-keyword">var</span> <span class="hljs-built_in">module</span> = installedModules[moduleId] = {
                <span class="hljs-comment">// &#x6A21;&#x5757;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x7684; index</span>
                i: moduleId,
                <span class="hljs-comment">// &#x8BE5;&#x6A21;&#x5757;&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x5B8C;&#x6BD5;</span>
                l: <span class="hljs-literal">false</span>,
                <span class="hljs-comment">// &#x8BE5;&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x51FA;&#x503C;</span>
                exports: {}
            };

            <span class="hljs-comment">// &#x4ECE; modules &#x4E2D;&#x83B7;&#x53D6; index &#x4E3A; moduleId &#x7684;&#x6A21;&#x5757;&#x5BF9;&#x5E94;&#x7684;&#x51FD;&#x6570;</span>
            <span class="hljs-comment">// &#x518D;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x540C;&#x65F6;&#x628A;&#x51FD;&#x6570;&#x9700;&#x8981;&#x7684;&#x53C2;&#x6570;&#x4F20;&#x5165;</span>
            modules[moduleId].call(<span class="hljs-built_in">module</span>.exports, <span class="hljs-built_in">module</span>, <span class="hljs-built_in">module</span>.exports, __webpack_require__);
            <span class="hljs-comment">// &#x628A;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x6807;&#x8BB0;&#x4E3A;&#x5DF2;&#x52A0;&#x8F7D;</span>
            <span class="hljs-built_in">module</span>.l = <span class="hljs-literal">true</span>;
            <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x8FD9;&#x4E2A;&#x6A21;&#x5757;&#x7684;&#x5BFC;&#x51FA;&#x503C;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-built_in">module</span>.exports;
        }

        <span class="hljs-comment">// Webpack &#x914D;&#x7F6E;&#x4E2D;&#x7684; publicPath&#xFF0C;&#x7528;&#x4E8E;&#x52A0;&#x8F7D;&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x7684;&#x5F02;&#x6B65;&#x4EE3;&#x7801;</span>
        __webpack_require__.p = <span class="hljs-string">&quot;&quot;</span>;

        <span class="hljs-comment">// &#x4F7F;&#x7528; __webpack_require__ &#x53BB;&#x52A0;&#x8F7D; index &#x4E3A; 0 &#x7684;&#x6A21;&#x5757;&#xFF0C;&#x5E76;&#x4E14;&#x8FD4;&#x56DE;&#x8BE5;&#x6A21;&#x5757;&#x5BFC;&#x51FA;&#x7684;&#x5185;&#x5BB9;</span>
        <span class="hljs-comment">// index &#x4E3A; 0 &#x7684;&#x6A21;&#x5757;&#x5C31;&#x662F; main.js &#x5BF9;&#x5E94;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6267;&#x884C;&#x5165;&#x53E3;&#x6A21;&#x5757;</span>
        <span class="hljs-comment">// __webpack_require__.s &#x7684;&#x542B;&#x4E49;&#x662F;&#x542F;&#x52A8;&#x6A21;&#x5757;&#x5BF9;&#x5E94;&#x7684; index</span>
        <span class="hljs-keyword">return</span> __webpack_require__(__webpack_require__.s = <span class="hljs-number">0</span>);

    })(

    <span class="hljs-comment">// &#x6240;&#x6709;&#x7684;&#x6A21;&#x5757;&#x90FD;&#x5B58;&#x653E;&#x5728;&#x4E86;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x91CC;&#xFF0C;&#x6839;&#x636E;&#x6BCF;&#x4E2A;&#x6A21;&#x5757;&#x5728;&#x6570;&#x7EC4;&#x7684; index &#x6765;&#x533A;&#x5206;&#x548C;&#x5B9A;&#x4F4D;&#x6A21;&#x5757;</span>
    [
        <span class="hljs-comment">/* 0 */</span>
        (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">module, exports, __webpack_require__</span>) </span>{
            <span class="hljs-comment">// &#x901A;&#x8FC7; __webpack_require__ &#x89C4;&#x8303;&#x5BFC;&#x5165; show &#x51FD;&#x6570;&#xFF0C;show.js &#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x5757; index &#x4E3A; 1</span>
            <span class="hljs-keyword">const</span> show = __webpack_require__(<span class="hljs-number">1</span>);
            <span class="hljs-comment">// &#x6267;&#x884C; show &#x51FD;&#x6570;</span>
            show(<span class="hljs-string">&apos;Webpack&apos;</span>);
        }),
        <span class="hljs-comment">/* 1 */</span>
        (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">module, exports</span>) </span>{
            <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">show</span>(<span class="hljs-params">content</span>) </span>{
                <span class="hljs-built_in">window</span>.document.getElementById(<span class="hljs-string">&apos;app&apos;</span>).innerText = <span class="hljs-string">&apos;Hello,&apos;</span> + content;
            }
            <span class="hljs-comment">// &#x901A;&#x8FC7; CommonJS &#x89C4;&#x8303;&#x5BFC;&#x51FA; show &#x51FD;&#x6570;</span>
            <span class="hljs-built_in">module</span>.exports = show;
        })
    ]
);
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x770B;&#x4E0A;&#x53BB;&#x590D;&#x6742;&#x7684;&#x4EE3;&#x7801;&#x5176;&#x5B9E;&#x662F;&#x4E00;&#x4E2A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x7B80;&#x5199;&#x4E3A;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js">(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">modules</span>) </span>{

  <span class="hljs-comment">// &#x6A21;&#x62DF; require &#x8BED;&#x53E5;</span>
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__webpack_require__</span>(<span class="hljs-params"></span>) </span>{
  }

  <span class="hljs-comment">// &#x6267;&#x884C;&#x5B58;&#x653E;&#x6240;&#x6709;&#x6A21;&#x5757;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x7B2C;0&#x4E2A;&#x6A21;&#x5757;</span>
  __webpack_require__(<span class="hljs-number">0</span>);

})([<span class="hljs-comment">/*&#x5B58;&#x653E;&#x6240;&#x6709;&#x6A21;&#x5757;&#x7684;&#x6570;&#x7EC4;*/</span>])
</code></pre>
<p><code>bundle.js</code> &#x80FD;&#x76F4;&#x63A5;&#x8FD0;&#x884C;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x7684;&#x539F;&#x56E0;&#x5728;&#x4E8E;&#x8F93;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x901A;&#x8FC7; <code>__webpack_require__</code> &#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x6267;&#x884C;&#x7684;&#x52A0;&#x8F7D;&#x51FD;&#x6570;&#x6765;&#x6A21;&#x62DF; Node.js &#x4E2D;&#x7684; <code>require</code> &#x8BED;&#x53E5;&#x3002;</p>
<p>&#x539F;&#x6765;&#x4E00;&#x4E2A;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#x88AB;&#x5408;&#x5E76;&#x5230;&#x4E86;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684; <code>bundle.js</code> &#x7684;&#x539F;&#x56E0;&#x5728;&#x4E8E;&#x6D4F;&#x89C8;&#x5668;&#x4E0D;&#x80FD;&#x50CF; Node.js &#x90A3;&#x6837;&#x5FEB;&#x901F;&#x5730;&#x53BB;&#x672C;&#x5730;&#x52A0;&#x8F7D;&#x4E00;&#x4E2A;&#x4E2A;&#x6A21;&#x5757;&#x6587;&#x4EF6;&#xFF0C;&#x800C;&#x5FC5;&#x987B;&#x901A;&#x8FC7;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x53BB;&#x52A0;&#x8F7D;&#x8FD8;&#x672A;&#x5F97;&#x5230;&#x7684;&#x6587;&#x4EF6;&#x3002;
&#x5982;&#x679C;&#x6A21;&#x5757;&#x6570;&#x91CF;&#x5F88;&#x591A;&#xFF0C;&#x52A0;&#x8F7D;&#x65F6;&#x95F4;&#x4F1A;&#x5F88;&#x957F;&#xFF0C;&#x56E0;&#x6B64;&#x628A;&#x6240;&#x6709;&#x6A21;&#x5757;&#x90FD;&#x5B58;&#x653E;&#x5728;&#x4E86;&#x6570;&#x7EC4;&#x4E2D;&#xFF0C;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x7F51;&#x7EDC;&#x52A0;&#x8F7D;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4ED4;&#x7EC6;&#x5206;&#x6790; <code>__webpack_require__</code> &#x51FD;&#x6570;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x4F60;&#x8FD8;&#x6709;&#x53D1;&#x73B0; Webpack &#x505A;&#x4E86;&#x7F13;&#x5B58;&#x4F18;&#x5316;&#xFF1A;
&#x6267;&#x884C;&#x52A0;&#x8F7D;&#x8FC7;&#x7684;&#x6A21;&#x5757;&#x4E0D;&#x4F1A;&#x518D;&#x6267;&#x884C;&#x7B2C;&#x4E8C;&#x6B21;&#xFF0C;&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4F1A;&#x7F13;&#x5B58;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x5F53;&#x67D0;&#x4E2A;&#x6A21;&#x5757;&#x7B2C;&#x4E8C;&#x6B21;&#x88AB;&#x8BBF;&#x95EE;&#x65F6;&#x4F1A;&#x76F4;&#x63A5;&#x53BB;&#x5185;&#x5B58;&#x4E2D;&#x8BFB;&#x53D6;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x3002;</p>
<h2 id="&#x5206;&#x5272;&#x4EE3;&#x7801;&#x65F6;&#x7684;&#x8F93;&#x51FA;">&#x5206;&#x5272;&#x4EE3;&#x7801;&#x65F6;&#x7684;&#x8F93;&#x51FA;</h2>
<p>&#x5728;&#x91C7;&#x7528;&#x4E86; <a href="../4&#x4F18;&#x5316;/4-12&#x6309;&#x9700;&#x52A0;&#x8F7D;.html">4-12 &#x6309;&#x9700;&#x52A0;&#x8F7D;</a> &#x4E2D;&#x4ECB;&#x7ECD;&#x8FC7;&#x7684;&#x4F18;&#x5316;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;Webpack &#x7684;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x4F1A;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x3002;</p>
<p>&#x4F8B;&#x5982;&#x628A;&#x6E90;&#x7801;&#x4E2D;&#x7684; <code>main.js</code> &#x4FEE;&#x6539;&#x4E3A;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x5F02;&#x6B65;&#x52A0;&#x8F7D; show.js</span>
<span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;./show&apos;</span>).then((show) =&gt; {
  <span class="hljs-comment">// &#x6267;&#x884C; show &#x51FD;&#x6570;</span>
  show(<span class="hljs-string">&apos;Webpack&apos;</span>);
});
</code></pre>
<p>&#x91CD;&#x65B0;&#x6784;&#x5EFA;&#x540E;&#x4F1A;&#x8F93;&#x51FA;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5206;&#x522B;&#x662F;&#x6267;&#x884C;&#x5165;&#x53E3;&#x6587;&#x4EF6; <code>bundle.js</code> &#x548C; &#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x6587;&#x4EF6; <code>0.bundle.js</code>&#x3002;</p>
<p>&#x5176;&#x4E2D; <code>0.bundle.js</code> &#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x52A0;&#x8F7D;&#x5728;&#x672C;&#x6587;&#x4EF6;(0.bundle.js)&#x4E2D;&#x5305;&#x542B;&#x7684;&#x6A21;&#x5757;</span>
webpackJsonp(
  <span class="hljs-comment">// &#x5728;&#x5176;&#x5B83;&#x6587;&#x4EF6;&#x4E2D;&#x5B58;&#x653E;&#x7740;&#x7684;&#x6A21;&#x5757;&#x7684; ID</span>
  [<span class="hljs-number">0</span>],
  <span class="hljs-comment">// &#x672C;&#x6587;&#x4EF6;&#x6240;&#x5305;&#x542B;&#x7684;&#x6A21;&#x5757;</span>
  [
    <span class="hljs-comment">// show.js &#x6240;&#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x5757;</span>
    (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">module, exports</span>) </span>{
      <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">show</span>(<span class="hljs-params">content</span>) </span>{
        <span class="hljs-built_in">window</span>.document.getElementById(<span class="hljs-string">&apos;app&apos;</span>).innerText = <span class="hljs-string">&apos;Hello,&apos;</span> + content;
      }

      <span class="hljs-built_in">module</span>.exports = show;
    })
  ]
);
</code></pre>
<p><code>bundle.js</code> &#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js">(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">modules</span>) </span>{
  <span class="hljs-comment">/***
   * webpackJsonp &#x7528;&#x4E8E;&#x4ECE;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x5B89;&#x88C5;&#x6A21;&#x5757;&#x3002;
   * &#x628A; webpackJsonp &#x6302;&#x8F7D;&#x5230;&#x5168;&#x5C40;&#x662F;&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x5728;&#x5176;&#x5B83;&#x6587;&#x4EF6;&#x4E2D;&#x8C03;&#x7528;&#x3002;
   *
   * @param chunkIds &#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x5B58;&#x653E;&#x7684;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x7684;&#x6A21;&#x5757;&#x5BF9;&#x5E94;&#x7684; Chunk ID
   * @param moreModules &#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x5B58;&#x653E;&#x7684;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x7684;&#x6A21;&#x5757;&#x5217;&#x8868;
   * @param executeModules &#x5728;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x5B58;&#x653E;&#x7684;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x7684;&#x6A21;&#x5757;&#x90FD;&#x5B89;&#x88C5;&#x6210;&#x529F;&#x540E;&#xFF0C;&#x9700;&#x8981;&#x6267;&#x884C;&#x7684;&#x6A21;&#x5757;&#x5BF9;&#x5E94;&#x7684; index
   */</span>
  <span class="hljs-built_in">window</span>[<span class="hljs-string">&quot;webpackJsonp&quot;</span>] = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">webpackJsonpCallback</span>(<span class="hljs-params">chunkIds, moreModules, executeModules</span>) </span>{
    <span class="hljs-comment">// &#x628A; moreModules &#x6DFB;&#x52A0;&#x5230; modules &#x5BF9;&#x8C61;&#x4E2D;</span>
    <span class="hljs-comment">// &#x628A;&#x6240;&#x6709; chunkIds &#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x5757;&#x90FD;&#x6807;&#x8BB0;&#x6210;&#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x6210;&#x529F; </span>
    <span class="hljs-keyword">var</span> moduleId, chunkId, i = <span class="hljs-number">0</span>, resolves = [], result;
    <span class="hljs-keyword">for</span> (; i &lt; chunkIds.length; i++) {
      chunkId = chunkIds[i];
      <span class="hljs-keyword">if</span> (installedChunks[chunkId]) {
        resolves.push(installedChunks[chunkId][<span class="hljs-number">0</span>]);
      }
      installedChunks[chunkId] = <span class="hljs-number">0</span>;
    }
    <span class="hljs-keyword">for</span> (moduleId <span class="hljs-keyword">in</span> moreModules) {
      <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Object</span>.prototype.hasOwnProperty.call(moreModules, moduleId)) {
        modules[moduleId] = moreModules[moduleId];
      }
    }
    <span class="hljs-keyword">while</span> (resolves.length) {
      resolves.shift()();
    }
  };

  <span class="hljs-comment">// &#x7F13;&#x5B58;&#x5DF2;&#x7ECF;&#x5B89;&#x88C5;&#x7684;&#x6A21;&#x5757;</span>
  <span class="hljs-keyword">var</span> installedModules = {};

  <span class="hljs-comment">// &#x5B58;&#x50A8;&#x6BCF;&#x4E2A; Chunk &#x7684;&#x52A0;&#x8F7D;&#x72B6;&#x6001;&#xFF1B;</span>
  <span class="hljs-comment">// &#x952E;&#x4E3A; Chunk &#x7684; ID&#xFF0C;&#x503C;&#x4E3A;0&#x4EE3;&#x8868;&#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x6210;&#x529F;</span>
  <span class="hljs-keyword">var</span> installedChunks = {
    <span class="hljs-number">1</span>: <span class="hljs-number">0</span>
  };

  <span class="hljs-comment">// &#x6A21;&#x62DF; require &#x8BED;&#x53E5;&#xFF0C;&#x548C;&#x4E0A;&#x9762;&#x4ECB;&#x7ECD;&#x7684;&#x4E00;&#x81F4;</span>
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__webpack_require__</span>(<span class="hljs-params">moduleId</span>) </span>{
    <span class="hljs-comment">// ... &#x7701;&#x7565;&#x548C;&#x4E0A;&#x9762;&#x4E00;&#x6837;&#x7684;&#x5185;&#x5BB9;</span>
  }

  <span class="hljs-comment">/**
   * &#x7528;&#x4E8E;&#x52A0;&#x8F7D;&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x7684;&#xFF0C;&#x9700;&#x8981;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684; Chunk &#x5BF9;&#x5E94;&#x7684;&#x6587;&#x4EF6;
   * @param chunkId &#x9700;&#x8981;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684; Chunk &#x5BF9;&#x5E94;&#x7684; ID
   * @returns {Promise}
   */</span>
  __webpack_require__.e = <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">requireEnsure</span>(<span class="hljs-params">chunkId</span>) </span>{
    <span class="hljs-comment">// &#x4ECE;&#x4E0A;&#x9762;&#x5B9A;&#x4E49;&#x7684; installedChunks &#x4E2D;&#x83B7;&#x53D6; chunkId &#x5BF9;&#x5E94;&#x7684; Chunk &#x7684;&#x52A0;&#x8F7D;&#x72B6;&#x6001;</span>
    <span class="hljs-keyword">var</span> installedChunkData = installedChunks[chunkId];
    <span class="hljs-comment">// &#x5982;&#x679C;&#x52A0;&#x8F7D;&#x72B6;&#x6001;&#x4E3A;0&#x8868;&#x793A;&#x8BE5; Chunk &#x5DF2;&#x7ECF;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x4E86;&#xFF0C;&#x76F4;&#x63A5;&#x8FD4;&#x56DE; resolve Promise</span>
    <span class="hljs-keyword">if</span> (installedChunkData === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve</span>) </span>{
        resolve();
      });
    }

    <span class="hljs-comment">// installedChunkData &#x4E0D;&#x4E3A;&#x7A7A;&#x4E14;&#x4E0D;&#x4E3A;0&#x8868;&#x793A;&#x8BE5; Chunk &#x6B63;&#x5728;&#x7F51;&#x7EDC;&#x52A0;&#x8F7D;&#x4E2D;</span>
    <span class="hljs-keyword">if</span> (installedChunkData) {
      <span class="hljs-comment">// &#x8FD4;&#x56DE;&#x5B58;&#x653E;&#x5728; installedChunkData &#x6570;&#x7EC4;&#x4E2D;&#x7684; Promise &#x5BF9;&#x8C61;</span>
      <span class="hljs-keyword">return</span> installedChunkData[<span class="hljs-number">2</span>];
    }

    <span class="hljs-comment">// installedChunkData &#x4E3A;&#x7A7A;&#xFF0C;&#x8868;&#x793A;&#x8BE5; Chunk &#x8FD8;&#x6CA1;&#x6709;&#x52A0;&#x8F7D;&#x8FC7;&#xFF0C;&#x53BB;&#x52A0;&#x8F7D;&#x8BE5; Chunk &#x5BF9;&#x5E94;&#x7684;&#x6587;&#x4EF6;</span>
    <span class="hljs-keyword">var</span> promise = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve, reject</span>) </span>{
      installedChunkData = installedChunks[chunkId] = [resolve, reject];
    });
    installedChunkData[<span class="hljs-number">2</span>] = promise;

    <span class="hljs-comment">// &#x901A;&#x8FC7; DOM &#x64CD;&#x4F5C;&#xFF0C;&#x5F80; HTML head &#x4E2D;&#x63D2;&#x5165;&#x4E00;&#x4E2A; script &#x6807;&#x7B7E;&#x53BB;&#x5F02;&#x6B65;&#x52A0;&#x8F7D; Chunk &#x5BF9;&#x5E94;&#x7684; JavaScript &#x6587;&#x4EF6;</span>
    <span class="hljs-keyword">var</span> head = <span class="hljs-built_in">document</span>.getElementsByTagName(<span class="hljs-string">&apos;head&apos;</span>)[<span class="hljs-number">0</span>];
    <span class="hljs-keyword">var</span> script = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">&apos;script&apos;</span>);
    script.type = <span class="hljs-string">&apos;text/javascript&apos;</span>;
    script.charset = <span class="hljs-string">&apos;utf-8&apos;</span>;
    script.async = <span class="hljs-literal">true</span>;
    script.timeout = <span class="hljs-number">120000</span>;

    <span class="hljs-comment">// &#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x4E3A;&#x914D;&#x7F6E;&#x7684; publicPath&#x3001;chunkId &#x62FC;&#x63A5;&#x800C;&#x6210;</span>
    script.src = __webpack_require__.p + <span class="hljs-string">&quot;&quot;</span> + chunkId + <span class="hljs-string">&quot;.bundle.js&quot;</span>;

    <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x6700;&#x957F;&#x8D85;&#x65F6;&#x65F6;&#x95F4;</span>
    <span class="hljs-keyword">var</span> timeout = setTimeout(onScriptComplete, <span class="hljs-number">120000</span>);
    script.onerror = script.onload = onScriptComplete;

    <span class="hljs-comment">// &#x5728; script &#x52A0;&#x8F7D;&#x548C;&#x6267;&#x884C;&#x5B8C;&#x6210;&#x65F6;&#x56DE;&#x8C03;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">onScriptComplete</span>(<span class="hljs-params"></span>) </span>{
      <span class="hljs-comment">// &#x9632;&#x6B62;&#x5185;&#x5B58;&#x6CC4;&#x9732;</span>
      script.onerror = script.onload = <span class="hljs-literal">null</span>;
      clearTimeout(timeout);

      <span class="hljs-comment">// &#x53BB;&#x68C0;&#x67E5; chunkId &#x5BF9;&#x5E94;&#x7684; Chunk &#x662F;&#x5426;&#x5B89;&#x88C5;&#x6210;&#x529F;&#xFF0C;&#x5B89;&#x88C5;&#x6210;&#x529F;&#x65F6;&#x624D;&#x4F1A;&#x5B58;&#x5728;&#x4E8E; installedChunks &#x4E2D;</span>
      <span class="hljs-keyword">var</span> chunk = installedChunks[chunkId];
      <span class="hljs-keyword">if</span> (chunk !== <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">if</span> (chunk) {
          chunk[<span class="hljs-number">1</span>](<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;Loading chunk &apos;</span> + chunkId + <span class="hljs-string">&apos; failed.&apos;</span>));
        }
        installedChunks[chunkId] = <span class="hljs-literal">undefined</span>;
      }
    };
    head.appendChild(script);

    <span class="hljs-keyword">return</span> promise;
  };

  <span class="hljs-comment">// &#x52A0;&#x8F7D;&#x5E76;&#x6267;&#x884C;&#x5165;&#x53E3;&#x6A21;&#x5757;&#xFF0C;&#x548C;&#x4E0A;&#x9762;&#x4ECB;&#x7ECD;&#x7684;&#x4E00;&#x81F4;</span>
  <span class="hljs-keyword">return</span> __webpack_require__(__webpack_require__.s = <span class="hljs-number">0</span>);
})
(
  <span class="hljs-comment">// &#x5B58;&#x653E;&#x6240;&#x6709;&#x6CA1;&#x6709;&#x7ECF;&#x8FC7;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#xFF0C;&#x968F;&#x7740;&#x6267;&#x884C;&#x5165;&#x53E3;&#x6587;&#x4EF6;&#x52A0;&#x8F7D;&#x7684;&#x6A21;&#x5757;</span>
  [
    <span class="hljs-comment">// main.js &#x5BF9;&#x5E94;&#x7684;&#x6A21;&#x5757;</span>
    (<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">module, exports, __webpack_require__</span>) </span>{
      <span class="hljs-comment">// &#x901A;&#x8FC7; __webpack_require__.e &#x53BB;&#x5F02;&#x6B65;&#x52A0;&#x8F7D; show.js &#x5BF9;&#x5E94;&#x7684; Chunk</span>
      __webpack_require__.e(<span class="hljs-number">0</span>).then(__webpack_require__.bind(<span class="hljs-literal">null</span>, <span class="hljs-number">1</span>)).then((show) =&gt; {
        <span class="hljs-comment">// &#x6267;&#x884C; show &#x51FD;&#x6570;</span>
        show(<span class="hljs-string">&apos;Webpack&apos;</span>);
      });
    })
  ]
);
</code></pre>
<p>&#x8FD9;&#x91CC;&#x7684; <code>bundle.js</code> &#x548C;&#x4E0A;&#x9762;&#x6240;&#x8BB2;&#x7684; <code>bundle.js</code> &#x975E;&#x5E38;&#x76F8;&#x4F3C;&#xFF0C;&#x533A;&#x522B;&#x5728;&#x4E8E;&#xFF1A;</p>
<ul>
<li>&#x591A;&#x4E86;&#x4E00;&#x4E2A; <code>__webpack_require__.e</code> &#x7528;&#x4E8E;&#x52A0;&#x8F7D;&#x88AB;&#x5206;&#x5272;&#x51FA;&#x53BB;&#x7684;&#xFF0C;&#x9700;&#x8981;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684; Chunk &#x5BF9;&#x5E94;&#x7684;&#x6587;&#x4EF6;;</li>
<li>&#x591A;&#x4E86;&#x4E00;&#x4E2A; <code>webpackJsonp</code> &#x51FD;&#x6570;&#x7528;&#x4E8E;&#x4ECE;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x5B89;&#x88C5;&#x6A21;&#x5757;&#x3002;</li>
</ul>
<p>&#x5728;&#x4F7F;&#x7528;&#x4E86; CommonsChunkPlugin &#x53BB;&#x63D0;&#x53D6;&#x516C;&#x5171;&#x4EE3;&#x7801;&#x65F6;&#x8F93;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x548C;&#x4F7F;&#x7528;&#x4E86;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x65F6;&#x8F93;&#x51FA;&#x7684;&#x6587;&#x4EF6;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x90FD;&#x4F1A;&#x6709; <code>__webpack_require__.e</code> &#x548C; <code>webpackJsonp</code>&#x3002;
&#x539F;&#x56E0;&#x5728;&#x4E8E;&#x63D0;&#x53D6;&#x516C;&#x5171;&#x4EE3;&#x7801;&#x548C;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x672C;&#x8D28;&#x4E0A;&#x90FD;&#x662F;&#x4EE3;&#x7801;&#x5206;&#x5272;&#x3002;</p>
<blockquote>
<p>&#x672C;&#x5B9E;&#x4F8B;<a href="http://webpack.wuhaolin.cn/5-2&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x5206;&#x6790;.zip" target="_blank">&#x63D0;&#x4F9B;&#x9879;&#x76EE;&#x5B8C;&#x6574;&#x4EE3;&#x7801;</a></p>
</blockquote>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="5-1工作原理概括.html" class="navigation navigation-prev " aria-label="Previous page: 5-1 工作原理概括">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="5-3编写Loader.html" class="navigation navigation-next " aria-label="Next page: 5-3 编写 Loader">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"5-2 输出文件分析","level":"1.7.2","depth":2,"next":{"title":"5-3 编写 Loader","level":"1.7.3","depth":2,"path":"5原理/5-3编写Loader.md","ref":"5原理/5-3编写Loader.md","articles":[]},"previous":{"title":"5-1 工作原理概括","level":"1.7.1","depth":2,"path":"5原理/5-1工作原理概括.md","ref":"5原理/5-1工作原理概括.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github-buttons"],"root":"./docs","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github-buttons":{"buttons":[{"user":"gwuhaolin","type":"follow","size":"small","width":"150"},{"user":"gwuhaolin","repo":"dive-into-webpack","type":"star","size":"small"}]},"sharing":{"facebook":false,"twitter":false,"google":false,"weibo":true,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"吴浩麟","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"isbn":"9787121331725","variables":{},"title":"深入浅出 Webpack","language":"zh-hans","gitbook":"*","description":"本书按照入门、配置、实战、优化、原理的路线层层深入，涵盖了 Webpack 的方方面面。对于小白，本书可以作为 Webpack 入门教程，对于老手，本书可以进一步加深你对 Webpack 的理解。"},"file":{"path":"5原理/5-2输出文件分析.md","mtime":"2021-07-01T07:20:17.248Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-07-01T07:20:58.537Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

